<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UploadController extends Controller
{
    public function upload(Request $request){
    	//接收到input file的图片
    	$file=$request->file('file');
    	//验证是否为合法的上传文件
    	if($file->isValid ()){
    		//将文件存储到date(‘ymd’)生成的文件夹下，而这个文件夹是在upload下，upload指的是config里面的filesystems.php里面
    		$path=$file->store (date ('ymd'),'upload');
			return ['file' => asset ('uploadImages/'.$path), 'code' => 0];
		}
	}
	public function editUpload(Request $request){
		//接收到input file的图片
		$file=$request->file('file');
		//验证是否为合法的上传文件
		if($file->isValid ()){
			//将文件存储到date(‘ymd’)生成的文件夹下，而这个文件夹是在upload下，upload指的是config里面的filesystems.php里面
			$path=$file->store (date ('ymd'),'upload');
			return [
				"success"   => true,
				"msg"       => "上传成功",
				"file_path" => asset ('uploadImages/'.$path)//文件地址
			];
		}
	}
}
